package com.jowell.mall.order.mq;

import com.jowell.mall.order.config.MQConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: Mr.ZJW
 * @Date: 2022-07-11 16:59
 * @Description: 消费者
 */
@Component
@RabbitListener(queues = MQConfig.FANOUT_QUERY)
public class Consumer {

    @RabbitHandler
    public void order(String msg, Message message, Channel channel) throws IOException {
        //消息编号
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            Thread.sleep(1000);
            System.out.println("receiver success  order->" + msg);
            //ack机制
            channel.basicAck(deliveryTag, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
